package com.bj58.ecdata.util;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang3.time.FastDateFormat;

/**
 * @author lichao
 *
 */
public class DateUtils extends org.apache.commons.lang3.time.DateUtils {

	public static long getTruncatedMinute() {
		return truncate(new Date(), Calendar.MINUTE).getTime();
	}

	public static long getTruncatedHour() {
		return truncate(new Date(), Calendar.HOUR).getTime();
	}

	public static long getTruncatedToday() {
		return truncate(new Date(), Calendar.DATE).getTime();
	}

	public static long truncateToMinute(long time) {
		return truncate(new Date(time), Calendar.MINUTE).getTime();
	}

	public static long truncateToHour(long time) {
		return truncate(new Date(time), Calendar.HOUR).getTime();
	}

	public static long truncateToToday(long time) {
		return truncate(new Date(time), Calendar.DATE).getTime();
	}

	/**
	 * @return yyyy-MM-dd HH:mm:ss
	 */
	public static String dateFormat(long date) {
		FastDateFormat dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
		return dateFormat.format(date);
	}
	
	public static String dateFormat(Date date,String pattern) {
		FastDateFormat dateFormat = FastDateFormat.getInstance(pattern);
		return dateFormat.format(date);
	}
	
	public static String dateFormat(long date,String pattern) {
		FastDateFormat dateFormat = FastDateFormat.getInstance(pattern);
		return dateFormat.format(date);
	}
}
